package main

import (
	"errors"
	"fmt"
	"strconv"
	"strings"
)

func main() {
	fmt.Println(ConvertToIntIP("1.0.168.192"))
	fmt.Println(ConvertToIntIP("192.168.0.1"))
	fmt.Println(ConvertToIntIP("255.255.255.255"))
}

func ConvertToIntIP(ip string) (int64, error) {
	ips := strings.Split(ip, ".")
	E := errors.New("Not A IP.")
	if len(ips) != 4 {
		return 0, E
	}
	var intIP int64
	for k, v := range ips {
		i, err := strconv.Atoi(v)
		if err != nil || i > 255 {
			return 0, E
		}
		// fmt.Println(k)
		intIP += int64(i) << (8 * (3 - k))
	}
	return intIP, nil
}
